package com.jjvu.news.service.impl;

import com.jjvu.news.dao.Info;
import com.jjvu.news.dao.MaxMenu;
import com.jjvu.news.domain.InfoDao;
import com.jjvu.news.service.InfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service("indexService")
public class InfoServiceImpl implements InfoService {
    @Autowired
    private InfoDao infoDao;
    public List<Info> findInfoListById(int i) {
        return infoDao.findInfoListById(i);
    }

    public List<MaxMenu> findMaxMenuList() {
        return infoDao.findMaxMenuList();
    }

    public Info findInfoById(Integer info_id) {
        //判断前端传输的数据是否有效
        if (info_id==null || info_id.equals("")){
            return null;
        }
        //更新点击率
        infoDao.updateHits(info_id);
        Info info = infoDao.findInfoById(info_id);
        return info;
    }

    public void setInfoDao(InfoDao infoDao) {
        this.infoDao = infoDao;
    }

    public List<Info> findAllNews(Integer maxid, Integer minid) {
        List<Info> allNews=new ArrayList<Info>();
        Info info=new Info();
        info.setMaxid(maxid);
        info.setMinid(minid);
        if (maxid!=null&&!maxid.equals("")){
            allNews=infoDao.findAllNewsBy(info);
        }
        if (minid!=null&&!minid.equals("")){
            allNews=infoDao.findAllNewsBy(info);
        }
        return allNews;
    }


}
